package com.ruoyi.xiaoshou.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.xiaoshou.domain.OrderAuditLog;
import com.ruoyi.xiaoshou.service.IOrderAuditLogService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 审核日志Controller
 * 
 * @author Rosou
 * @date 2025-06-17
 */
@Controller
@RequestMapping("/xiaoshou/log")
public class OrderAuditLogController extends BaseController
{
    private String prefix = "xiaoshou/log";

    @Autowired
    private IOrderAuditLogService orderAuditLogService;

    @RequiresPermissions("xiaoshou:log:view")
    @GetMapping()
    public String log()
    {
        return prefix + "/log";
    }

    /**
     * 查询审核日志列表
     */
    @RequiresPermissions("xiaoshou:log:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OrderAuditLog orderAuditLog)
    {
        startPage();
        List<OrderAuditLog> list = orderAuditLogService.selectOrderAuditLogList(orderAuditLog);
        return getDataTable(list);
    }

    /**
     * 导出审核日志列表
     */
    @RequiresPermissions("xiaoshou:log:export")
    @Log(title = "审核日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(OrderAuditLog orderAuditLog)
    {
        List<OrderAuditLog> list = orderAuditLogService.selectOrderAuditLogList(orderAuditLog);
        ExcelUtil<OrderAuditLog> util = new ExcelUtil<OrderAuditLog>(OrderAuditLog.class);
        return util.exportExcel(list, "审核日志数据");
    }

    /**
     * 新增审核日志
     */
    @RequiresPermissions("xiaoshou:log:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存审核日志
     */
    @RequiresPermissions("xiaoshou:log:add")
    @Log(title = "审核日志", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(OrderAuditLog orderAuditLog)
    {
        return toAjax(orderAuditLogService.insertOrderAuditLog(orderAuditLog));
    }

    /**
     * 修改审核日志
     */
    @RequiresPermissions("xiaoshou:log:edit")
    @GetMapping("/edit/{auditId}")
    public String edit(@PathVariable("auditId") Long auditId, ModelMap mmap)
    {
        OrderAuditLog orderAuditLog = orderAuditLogService.selectOrderAuditLogByAuditId(auditId);
        mmap.put("orderAuditLog", orderAuditLog);
        return prefix + "/edit";
    }

    /**
     * 修改保存审核日志
     */
    @RequiresPermissions("xiaoshou:log:edit")
    @Log(title = "审核日志", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OrderAuditLog orderAuditLog)
    {
        return toAjax(orderAuditLogService.updateOrderAuditLog(orderAuditLog));
    }

    /**
     * 删除审核日志
     */
    @RequiresPermissions("xiaoshou:log:remove")
    @Log(title = "审核日志", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(orderAuditLogService.deleteOrderAuditLogByAuditIds(ids));
    }
}
